﻿using System;
using CCS.Properties;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace CCS
{
    public class StorageClientHelper
    {
        private static TableStorage tableStorage;
        private static StorageAccountInfo accountInfo;

        private StorageClientHelper()
        {
        }

        public static StorageAccountInfo GetAccountInfo()
        {
            if (accountInfo == null)
            {
                accountInfo = new StorageAccountInfo(Settings.Default.TableStorageEndpoint, true,
                                                     Settings.Default.AzureTableAccountName,
                                                     Settings.Default.AzureAccountSharedKey);
            }
            return accountInfo;
        }

        public static TableStorage GetTableStorage()
        {
            if (tableStorage == null)
            {
                tableStorage = TableStorage.Create(GetAccountInfo());
                tableStorage.RetryPolicy = RetryPolicies.RetryN(Settings.Default.RetryPoliciesRetryN,
                                                                TimeSpan.FromSeconds(Settings.Default.RetryPoliciesWait));
            }
            return tableStorage;
        }
    }
}